package com.chen.apidriver.service;

import com.chen.apidriver.remote.ServiceDriverUserClient;
import com.chen.apidriver.remote.ServiceMapClient;
import com.chen.internalcommon.dto.Car;
import com.chen.internalcommon.dto.ResponseResult;
import com.chen.internalcommon.request.ApiDriverPointRequest;
import com.chen.internalcommon.request.PointRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author chenLiuPing
 **/
@Service
@Slf4j
public class PointService {

    @Autowired
    private ServiceDriverUserClient serviceDriverUserClient;

    @Autowired
    private ServiceMapClient serviceMapClient;

    public ResponseResult upload(ApiDriverPointRequest apiDriverPointRequest) {
        Long carId = apiDriverPointRequest.getCarId();
        // 根据carId 调用service-driver-user查询到对应的car获取tid和trid
        Car car = serviceDriverUserClient.getCarById(carId).getData();
        log.info("根据carId{}获取到的car：{}", carId, car);
        String trid = car.getTrid();
        String tid = car.getTid();
        // 根据获取到的tid trid 调用service-map 完成轨迹上传
        PointRequest pointRequest = new PointRequest(tid, trid, apiDriverPointRequest.getPoints());
        return serviceMapClient.upload(pointRequest);
    }
}
